/**
 *
 */
package commons.beancopier.mapper;

import org.apache.commons.collections.map.LRUMap;


/**
 * @author 陌铭(Phenix Huang)
 *
 */
public abstract class AbstractPropertiesMapperBuilder implements PropertiesMapperBuilder {
    private LRUMap localCache = new LRUMap(20);

    /*
     * @see net.phenix.comp.util.bean.mapper.ClassMapperSet#getMapper(java.lang.Class)
     */
    public final PropertiesMapper getMapper(Class<?> clz) {
        if (needToExclude(clz)) {
            return null ;
        }
        PropertiesMapper mapper = null ;
        synchronized (localCache) {
            mapper = (PropertiesMapper)localCache.get(clz);
            if (mapper == null) {
                mapper = createMapper(clz);
                localCache.put(clz, mapper);
            }
        }
        return mapper ;
    }

    public abstract boolean needToExclude(Class<?> clz) ;

    public abstract PropertiesMapper createMapper(Class<?> clz) ;
}
